package com.szd.interceptor;

import com.szd.pojo.SysUser;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/*
* @Date
* @登录拦截器
*
* */
public class LoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        HttpSession session = request.getSession();
        SysUser user=(SysUser)session.getAttribute("USER_SESSION");
        if(user==null){
            response.sendRedirect(request.getContextPath()+"/user/to_login");
            return false;
        }

        return true;
    }
}
